package com.suixinsanren.design.compound.demo02;

import java.util.ArrayList;
import java.util.List;

public class Observable implements QuackObservable {

    private List<Observer> observers;
    private final QuackAble quackAble;

    public Observable(QuackAble quackAble) {
        this.quackAble = quackAble;
        observers = new ArrayList<>();
    }

    @Override
    public void addObserver(Observer observer) {
        observers.add(observer);
    }

    @Override
    public void notifyObserver() {
        observers.forEach(observer -> observer.update(quackAble));
    }
}
